refactor: add STRAIGHT_JOIN prefix for MySQL query optimization in get_sorted_triggers#46303
Conversation
|
Could someone please take a look at this? @ashb @XD-DENG @dstandish @hussein-awala |
|
It does seem it's good idea:
https://dev.mysql.com/doc/refman/8.4/en/join.html @ashb @XD-DENG @dstandish @hussein-awala -> anything against it? |
ef8df34 to
7378b81
Compare
|
I would like to include this change in the upcoming 2.10.6 version. Is that possible? If yes, what would be the process? |
|
There are conflicts to resolve |
7378b81 to
8f66666
Compare
|
I missed the conflicts. I've resolved them now. |
…t_sorted_triggers
8f66666 to
66eee24
Compare
|
Hello, this PR was approved but hasn't been merged for a while. Could someone please help with merging it? Thanks in advance! |
…_triggers (#46303) This PR adds a STRAIGHT_JOIN hint to prevent an unintended full scan of TaskInstance table in get_sorted_triggers. With MySQL backend, if there are many records in the trigger, it causes the task_instance to be scanned first as the driving table, leading to slow queries. (cherry picked from commit 9f0ac9a)
…_triggers (apache#46303) This PR adds a STRAIGHT_JOIN hint to prevent an unintended full scan of TaskInstance table in get_sorted_triggers. With MySQL backend, if there are many records in the trigger, it causes the task_instance to be scanned first as the driving table, leading to slow queries.
This PR adds a
STRAIGHT_JOINhint to prevent an unintended full scan inget_sorted_triggers.With MySQL backend, if there are many records in the
trigger, it causes thetask_instanceto be scanned first as the driving table, leading to slow queries.To test this, I stopped the
triggererprocess to keep it unassigned first, and generated some dummy data, as shown below:With the following 10 records where the triggerer is not assigned:
The execution plan of the AS-IS query shows that it does a full scan of
task_instancefirst, causing a slowdown of the query due to the unnecessary scan.When adding
.prefix_with("STRAIGHT_JOIN", dialect="mysql"), the compiled SQL execution plan improved as shown below:In the case of PostgreSQL, regardless of the number of records in the trigger, the execution plan remains the same and efficient as shown below: